<?php
namespace Admin\Controller;
//工具类
use Admin\Common\Tools as T;
//逻辑类
use Admin\Common\Logic;

use Admin\Common\Api\UserApi;
use Admin\Common\POMVIPClient as VIP;
// use Admin\Common\POMNetTools as T;

class UserController extends BaseController {
    private $HAND_LOGINC   = null;
    private $HAND_USER   = null;
    //管理员用户列表
    public function index(){
       $this->display();

  }

   public function admin_list(){
     $title =I('request.title','','trim');
        if(!empty($title)){
           $where['name|email'] =array('like',"%{$title}%");
           // print_r($_where);exit;
           // $_where['parcelname']=array('like',"%{$keywords}%");
        }
         $where['is_activity'] = 1;
        $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = '*';
        $_where_order_field["order"] = 'id desc';
        $_datalist= $this->_getListsFromModel('user',$_where_order_field);
        // print_r($_datalist['page_html']);exit;
        $this->assign('lists',$_datalist);
        $this->display();

   }

   //修改密码,密码验证
   public function  upd_pwd(){
       if(IS_POST){
        $pwd =I('request.pwd','','trim');
        $this->HAND_USER = new UserApi();

        if($this->HAND_USER->upd_pwd($pwd)){
         $this->ajaxreturn(array('state'=>1,'msg'=>'原密码正确'));
        }else{
         $this->ajaxreturn(array('state'=>0,'msg'=>'原密码错误'));
        }
       }else{
        $this->display('upd_pwd');
       }

   }

   //验证用户名是否一样
   public function  is_username(){
        $username =I('request.username','','trim');
        $this->HAND_USER = new UserApi();
        if($this->HAND_USER->is_username(strval($username))){
         $this->ajaxreturn(array('state'=>0,'msg'=>'用户名存在'));
        }else{
         $this->ajaxreturn(array('state'=>1,'msg'=>'用户名可用'));
        }

   }
   //修改密码,提交到数据库
   public function  save_pwd(){
       if(IS_AJAX){
        $old_pwd =I('request.old_pwd','','trim');
        $new_pwd =I('request.new_pwd','','trim');
        $re_pwd =I('request.re_pwd','','trim');
        if($new_pwd != $re_pwd){
          $this->ajaxreturn(array('state'=>0,'msg'=>'两次输入的密码不一致'));
        }
        if($old_pwd == $new_pwd){
          $this->ajaxreturn(array('state'=>0,'msg'=>'新密码不能与原密码一样'));
        }

        $this->HAND_USER = new UserApi();
        if($this->HAND_USER->save_pwd($new_pwd)){
           $this->ajaxreturn(array('state'=>1,'msg'=>'密码修改成功'));
        }else{
           $this->ajaxreturn(array('state'=>0,'msg'=>'密码修改失败'));
        }
       }

}


public function  api_html(){
  $VIPClient = new VIP();
  $VIPClient->initOAuth();
  $ret = M("oauth")->where("is_deleted=0")->find();
  $re = $VIPClient->GetVipInfo();
  $this->assign('key_code',$re["KeyCode"]);
  $this->assign('app_key',$ret["app_key"]);
  $this->assign('app_secret',$ret["app_secret"]);

    $this->display();

}

public function  help(){
    $this->display();

}
}
